<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>.: BooMS v1.0 :.</title>
<link type="text/css" rel="stylesheet" href="<?php echo base_url();?>css/reset.css" />
<link type="text/css" rel="stylesheet" href="<?php echo base_url();?>css/960.css" />
<link type="text/css" rel="stylesheet" href="<?php echo base_url();?>css/main.css" />
<script type="text/javascript" src="<?php echo base_url();?>js/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>js/jquery-ui-1.8.9.custom.min.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>js/jquery.validate.js"></script>
</head>
<body>
<div id="wrap">
	<div id="top">
        <div id="globalNavigation">
        	<div id="user">
            	<ul>
                	<li><a href="#">Change info</a></li>
                    <li><a href="#">Log out</a></li>
                </ul>
            </div>
        	<div id="logo">
            	<h1>BooMS</h1>
                <p><em>Boo's website content management</em></p>
            </div>
        	<div id="menu">
                <ul>
                    <li><a href="<?php echo site_url().'/product/'?>">Product</a></li>
                    <li><a href="<?php echo site_url().'/brand/'?>">Brand</a></li>
                    <li class="selected"><a href="<?php echo site_url().'/advertisment/'?>">Advertiment</a></li>
                    <li><a href="#"></a></li>
                </ul>
            </div>
            <div class="clear"></div>
        </div>
    </div>
    <div id="middle">
    	<div id="middleWrap" class="container_24">
        	<h1>Advertisment Management</h1>
            <div id="advertisment" class="gridType grid_14">
            	<div id="gridHeader">
	                <div class="grid_1">&nbsp;</div>
                    <div class="grid_3">Title</div>
                    <div class="grid_3">Content</div>
                    <div class="grid_3">Type</div>
                    <div class="grid_1">Order</div>
                    <div class="grid_1">status</div>
                    <div class="clear"></div>
    			</div>
                <div class="gridBody">
                <form action="" method="post" id="frm_selected_box" name="frm_selected_box">
                 <?php  foreach($advertisments as $row):?>
                    <div class="gridItem evenRow">
                        <div class="grid_1" >
                            <input type="checkbox" value="<?php echo $row->adv_id; ?>" name="selected_box[]">
                        </div>
                        <div class="grid_3"><a href="#" class="bid" id="<?php echo $row->adv_id; ?>"><?php echo $row->adv_title; ?></a></div>
                        <div class="grid_3"><a href="#" class="bid" id="<?php echo $row->adv_id; ?>"><?php echo $row->adv_content; ?></a></div>
                        <div class="grid_3"><a href="#" id="<?php echo $row->adv_type; ?>"><?php if(isset($row->adv_type)) {echo $row->adv_type;} else {echo '---';} ?></a></div>
                        <div class="grid_1" >
                            <input type="text" style="width:30px;" value="<?php echo $row->ordering; ?>" name="arr_ordering[]">
                        </div>
                        <div class="grid_1">
							<?php if($row->status==1){ ?>
                                    <img src="<?php echo base_url();?>images/accept.png" id="1" alt="Show" title="Show" class="status">
                            <?php }else{ ?>
                                    <img src="<?php echo base_url();?>images/cancel.png" id="0" alt="Not Show" title="Not Show"  class="status">
                            <?php } ?>  
                        </div>                            
	                    <div class="clear"></div>
                	</div>
                 <?php endforeach; ?>
                  </form>
           		</div>
            </div>
            <div id="formWrap" class="grid_10">
            <form id="frm" name="frm" action="" method="post">
            	<div class="formItem text">
                    <div class="grid_2 alpha"><label for="advertisment_title">Name:</label></div>
                    <div class="grid_8 omega"><input type="text" class="large required" id="advertisment_title" name="advertisment_title"  value="" /></div>
                    <div class="clear"></div>
                </div>
                <div class="formItem text">
                    <div class="grid_2 alpha"><label for="advertisment_content">Content(image):</label></div>
                    <div class="grid_8 omega"><input type="text" class="large" id="advertisment_content" name="advertisment_content"  value="" /></div>
                    <div class="clear"></div>
                </div>
                <div class="formItem text">
                    <div class="grid_2 alpha"><label for="advertisment_type">Type(Position):</label></div>
                    <div class="grid_8 omega"><input type="text" class="large" id="advertisment_type" name="advertisment_type"  value="" /></div>
                    <div class="clear"></div>
                </div>
                <div class="formItem text">
                    <div class="grid_2 alpha"><label for="ordering">Order:</label></div>
                    <div class="grid_8 omega"><input type="text" class="small" id="ordering" name="ordering"  value="0" /></div>
                    <div class="clear"></div>
                </div>
                <div class="formItem optionbox">
                    <div class="grid_2 alpha"><label for="bStatus">Show:</label></div>
                    <div class="grid_6 omega">
                        Yes<input type="radio" id="show" class="status" checked name="status" value="1" />&nbsp;
                        No<input type="radio" id="not_show" class="status"   name="status" value="0" /> 
                    </div>          
                    
                    <div class="grid_2 alpha"><label for=""></label></div>
                     <br /><br />
                    <div class="grid_6 omega">
                        <input type="button" value="Save"  name="btn_submit" id="btn_submit" /> &nbsp;
                         <input type="reset" value="Cancel" name="btn_cancel" id="btn_reset"/>
                    </div>
                    <div class="clear"></div>
                </div>
                <hr />
                <div class="otherAction">
                    
                </div>   
            </form>
            </div>
            <div class="clear"></div>
            <div class="actionBar product">
            	<div id="gridHeader">
	                <div class="grid_1">&nbsp;</div>
                    <div class="grid_3">Title</div>
                    <div class="grid_3">Content</div>
                    <div class="grid_3">Type</div>
                    <div class="grid_1">Order</div>
                    <div class="grid_1">status</div>
                    <div class="clear"></div>
    			</div>
            	<div class="actionMenu grid_9">
                
            	<ul class="function">
                    <li><a href="#" id="btn_add">Add</a></li>
                    <li><a href="#" id="btn_edit">Edit</a></li>
                    <li><a href="#" id="btn_delete">Delete</a></li>
                    <li id ="save_add" ><a href="#" id="btn_save_add" >Save</a></li>
                    <li id ="save_edit"><a href="#" id="btn_save_edit" >Save</a></li>
                </ul>
                </div>
                <div class="pagination grid_5"><?php echo $pagination;?></div>
            </div>
        </div>
    </div>
    <div id="bottom">
    	<div class="threeCol"></div>
        <div class="threeCol"></div>
        <div class="threeCol"></div>
        <div class="clear"></div>
    </div>
</div>
<script>
	// set default btn_submit
	$("#frm").attr('action','<?php echo base_url();?>index.php/advertisment/add');
	// set button Save Add + Save Edit default
	$('#save_add').hide();
	$('#save_edit').hide();
	// set focus form add
	$('#adv_title').focus();
	// Post ajax : click advertisment code(alias) send advertisment value to from edit	
	$('.bid').click(function(){
	var id = $(this).attr('id');
    $('#advertisment_id').val(id);
		$.ajax({
			url: '<?php echo base_url(); ?>index.php/advertisment/index?action=edit',
			data:{advertisment_id: id},
			type:'POST',
			success: function(data){
			  		$('#advertisment_content').val(data.adv_content);
                    $('#advertisment_title').val(data.adv_title);
                    $('#advertisment_type').val(data.adv_des);
					if(data.status==1){
						$('#show').attr('checked','checked');
					}else{
						$('#not_show').attr('checked','checked');
					}
			  },
             dataType:"json" 
		});
		$("#frm").attr('action','<?php echo base_url();?>index.php/advertisment/edit');
	});
    //------------ Menu bottom------------------
	// Button Add
    $('#btn_add').click(function(){
		$('#save_edit').hide();
    	$('#advertisment_title').focus();
		$('#save_add').show();
		$('#advertisment_content').attr('value','');
		$('#advertisment_title').attr('value','');
		$('#advertisment_type').attr('value','');	
    });
	// Button Edit
	$('#btn_edit').click(function(){
		$('#save_add').hide();
		$('#save_edit').show();
		$('#advertisment_title').focus();
    });
	// Button Save for add action
	$('#btn_save_add').click(function(){
    	//$.ajax({
//			  url: '<?php //echo base_url(); ?>index.php/advertisment/add',
//			  type:'POST',
//			  data:$('#frm').serialize(),
//			  success: function(){		 	
//			  }
//		});
		$("#frm").attr('action','<?php echo base_url();?>index.php/advertisment/add');
		$("#frm").submit();
    });
	// Button Save for edit action
	$('#btn_save_edit').click(function(){
    	//$.ajax({
//			  url: '<?php // echo base_url(); ?>index.php/advertisment/edit',
//			  type:'POST',
//			  data:  $('#frm').serialize(),
//			  success: function(){		 	  
//			  }
//		});
		$("#frm").attr('action','<?php echo base_url();?>index.php/advertisment/edit');
		$("#frm").submit();
		$("#frm").attr('action','<?php echo base_url();?>index.php/advertisment/add');
    });
	// Button delete	
	 $('#btn_delete').click(function(){
		if($('input[name="selected_box[]"]').is(':checked')){// jquery 1.6+
			 if(confirm('You want delete this(these) avertisment(s) ?') ==1){
				 $(":checkbox").click(function(){
					var id_delete_array = $('#frm_selected_box').serialize();	  	 
				 });
				 //$.ajax({
//					  url: '<?php //echo base_url(); ?>index.php/advertisment/delete',
//					  type:'POST',
//					  data:$('#frm_selected_box').serialize(),
//					  success: function(data){		 
//					  }
//				});
				$("#frm_selected_box").attr('action','<?php echo base_url();?>index.php/advertisment/delete');
				$("#frm_selected_box").submit();
			  }
		}else{alert('You need selecte before delete !'); }
	 });
   // Link seelct advertisment filter product 
	$('.actionBtn').click(function(){
		$.ajax({
			 url: '<?php echo base_url(); ?>index.php/advertisment/index',
			 type:'POST',
			 data: $('#frm').serialize(),
			 success: function(){
			 }
		});
	});
	//------------ End menu bottom-------------------------
	
	// Form Action
	// quick save
	$('#btn_submit').click(function(){
		 $("#frm").submit();
		 $("#frm").attr('action','<?php echo base_url();?>index.php/advertisment/add');
	});
	//frm validate
	jQuery.validator.addMethod("noSpace", function(value, element) { // add method: not allow white-space
	  return value.indexOf(" ") < 0 && value != ""; 
	}, "No space please and don't leave it empty");
	
	//Press Enter submit form
	$('#advertisment_content,#advertisment_title,#advertisment_type').keypress(function(e){
		if (( e.which == 13 ) || (e.keycode==13))
		{
			$('#btn_submit').click();
		}
	});
</script>
</body>
</html>
